/**
 * Copyright 2011 Enjoy Change, Inc. All rights reserved.
 * Use is subject to license terms.
 */
package com.enjoychange.enjoy.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.enjoychange.enjoy.application.IAccountService;
import com.enjoychange.enjoy.domain.Account;
import com.enjoychange.enjoy.exception.AccountException;

/**
 * @author Administrator
 * @date   May 30, 2011
 */
@Controller
public class AccountController {
	
	@Autowired
	IAccountService accountService;
	@RequestMapping("/registry.do")
	public String registry(HttpServletRequest request,Account account) throws AccountException{
		
		this.accountService.createAccount(account);
		
		return "index";
	}
	@RequestMapping("/signup.do")
	public String signUp(HttpServletRequest request){
				
		return "signup";
	}
	@RequestMapping("/signin.do")
	public String signIn(HttpServletRequest request){
				
		return "signin";
	}
	@RequestMapping("/login.do")
	public String login(HttpServletRequest request,Account account) throws AccountException{
		accountService.login(account);
		request.getSession(false).setAttribute("logged_user", account);
		request.getSession(false).setAttribute("logged_username", account.getEmail());
		return "index";
	}

}